 #include <iostream>
#include <cmath>
#include <unordered_map>

/**
 * @brief Checks if a given number is prime.
 *
 * @param n The number to be checked.
 * @return true if the number is prime, false otherwise.
 */
bool a(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(std::sqrt(n)) + 1; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

/**
 * @brief Finds the next prime number greater than or equal to the given number.
 *
 * @param u The starting number.
 * @return The next prime number.
 */
int m(int u) {
    while (true) {
        if (a(u)) {
            return u;
        }
        u++;
    }
}

/**
 * @brief Converts a word to its corresponding integer value.
 *
 * @param o The word to be converted.
 * @return The integer value of the word, or -1 if the word is not recognized.
 */
int w(std::string o) {
    std::unordered_map<std::string, int> numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    auto it = numbers.find(o);
    if (it != numbers.end()) {
        return it->second;
    } else {
        return -1;
    }
}

/**
 * @brief The main function that takes user input, converts the words to numbers, and finds the next prime number.
 */
int main() {
    std::string input;
    std::cout << "Введите три слова: ";
    std::getline(std::cin, input);

    std::size_t spacePos = 0;
    std::size_t prevSpacePos = 0;
    std::string words[3];
    int wordIndex = 0;

    while ((spacePos = input.find(" ", prevSpacePos)) != std::string::npos) {
        words[wordIndex++] = input.substr(prevSpacePos, spacePos - prevSpacePos);
        prevSpacePos = spacePos + 1;
    }
    words[wordIndex] = input.substr(prevSpacePos);

    if (wordIndex != 2) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    int num = 0;
    for (int i = 0; i < 3; i++) {
        int number = w(words[i]);
        if (number == -1) {
            std::cout << "Wrong input" << std::endl;
            return 1;
        }
        num = num * 10 + number;
    }

    if (num >= 100 && num <= 999) {
        int res = m(num);
        std::cout << res << std::endl;
    } else {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}

